* tab1.do	JEP 	5/10/2015
* Builds table 1, sample sizes by mw incidence, city, formality , industry

*************************** Change log ********************************** 

/*
	
*/	

clear 
version 13.1

* Project info
cap project, doinfo
if _rc==198 {
	if c(os)=="Unix" loc master "/home/jperez/AA_Minimum_Wage" 
 else if c(username)=="J16339" loc master "B:\Col_Minimum_Wage"
 else if c(username)=="A15858" loc master "B:\Col_Minimum_Wage"
	else loc master "C:/Users/jorpp/Dropbox (Brown)/Col_Minimum_Wage"
	loc pr=0
}
else {
	local master "`r(pdir)'"
	local doname "`r(dofile)'" 
	* Project calls
	project, uses("`master'/Data/Source/ocupados_mw.dta")
	* Call programs
	project, relies_on("`master'/Code/Est/sample_choice.do")
	project, relies_on("`master'/Code/Est/build_mw_measures.do")
	project, relies_on("`master'/Code/Est/build_treatment.do")	
	loc pr=1
}
*/


* Call necessary programs. I do not call using project to carry the programs around. I do not put these in the ado/personal folder because they are specific to the project. They are not ado files.
do "`master'/Code/Est/sample_choice.do"
do "`master'/Code/Est/build_mw_measures.do"
do "`master'/Code/Est/build_treatment.do"

glo outdir "`master'/Doc/tosubmit2/tab"

* Draw graph for formal sector
use "`master'/Data/Source/ocupados_mw.dta", clear
graph drop _all
* Choose samples - get them from the estimates
mysample rif4sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) formal exind(13,29,42)
* est use "`master'/Ster/rif4new_ind/reg_ct_emp_bp_ixc_tq(1998q4)_bite_salario_mensual_real_50_edom_ind_p50.ster"
* replace rif4sample = rif4sample & e(sample)
mysample rif10sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) informal exind(13,29,42)
* est clear 
* est use "`master'/Ster/rif10new_ind/reg_ct_emp_bp_ixc_tq(1998q4)_bite_salario_mensual_real_50_edom_ind_p50.ster"
* replace rif10sample = rif10sample & e(sample)
mw_measures rif4sample , stub(rif4)
mytreatment, posts("tq(1999q1)") mw(bite_rif4_ind) wage(salario_mensual_real)


keep if rif4sample | rif10sample 
count

la var sexo "Gender"
la define sexolab 1 "Male" 2 "Female"
la val sexo sexolab

gen cedad2=recode(edad,17,25,50,65)	

la var cedad2 "Age"
la define cedad2lab 17 "12-17" 25 "18-25" 50 "26-50" 65 "51-65"
la val cedad2 cedad2lab

* Educ la paso para tabla 3

gen ceduc=.
replace ceduc=1 if educ<=5
replace ceduc=2 if educ>5 & educ <=11
replace ceduc=3 if educ>11 & educ<=17
replace ceduc=4 if educ>17

la var ceduc "Years of schooling"
la define ceduclab 1 "0-5" 2 "6-11" 3 "12-17" 4 "more than 17"
la val ceduc ceduclab
 
gen wm=.
replace wm = 1 if salario_mensual_real < 0.97*minw_mensual_real
replace wm = 2 if salario_mensual_real >= 0.97*minw_mensual_real & salario_mensual_real<=1.03*minw_mensual_real
replace wm = 3 if salario_mensual_real > 1.03*minw_mensual_real

la define wmlab 1 "Below" 2 "At" 3 "Above"
la val wm wmlab
la var wm "Relative to Minimum wage"

* drop if cactividad_empresa==.

la var tipo_trabajador "Sector"
la define tipolab 2 "Private" 3 "Government" 4 "Domestic"
la val tipo_trabajador tipolab

gen f=.
replace f=1 if rif4sample
replace f=2 if rif10sample
la var f "Informality"
la define flab 1 "Formal" 2 "Informal"
la val f flab

gen sdd=salario_mensual_real /2000

tabout f using "$outdir/wages.tex" [aw=fex] , c(mean sdd p10 sdd p25 sdd p50 sdd p75 sdd p90 sdd  ) topf($outdir/top.tex) botf($outdir/bot.tex) f(1c) /* layout(cb) */ style(tex) font(bold) bt /* cl1(2-9 ptotal(none)  */ replace npos(row) nlab(Sample size) sum oneway h3(nil)

if `pr' project, creates("$outdir/wages.tex")

cd $outdir

*maketex using wages.tex, packages(booktabs tabularx)
*!pdflatex  wages.tex
*!wages.pdf





